﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;


namespace SnakeX
{
	/// <summary>
	/// This class can draw a Direct3D square.
	/// </summary>
	public class SnakeXSquare
	{
		/// <summary>
		/// Constructor.
		/// Initializing members.
		/// </summary>
		/// <param name="d3dDevice">The device to use when drawing a square.</param>
		public SnakeXSquare(Device d3dDevice)
		{
			this.d3dDevice = d3dDevice;
		}
	

		/// <summary>
		/// Drawing a square with the given parameters on the device.
		/// </summary>
		/// <param name="startPos">Square start position</param>
		/// <param name="side">Square side length</param>
		/// <param name="color">Suqare fill color</param>
		public void Draw(System.Drawing.Point startPos, int side, 
			System.Drawing.Color color)
		{
			// Creating square vertex.
			CustomVertex.TransformedColored[] Verts =
				 new CustomVertex.TransformedColored[4];

			Verts[0] = new CustomVertex.TransformedColored(new
				 Vector4((float)startPos.X,
						 (float)startPos.Y, 0.0f, 1.0f),
				 color.ToArgb());

			Verts[1] = new CustomVertex.TransformedColored(new
				 Vector4((float)(startPos.X + side),
						 (float)startPos.Y, 0.0f, 1.0f),
				 color.ToArgb());

			Verts[2] = new CustomVertex.TransformedColored(new
				Vector4((float)startPos.X,
						 (float)(startPos.Y + side), 0.0f, 1.0f),
				color.ToArgb());

			Verts[3] = new CustomVertex.TransformedColored(new
				 Vector4((float)(startPos.X + side),
						 (float)(startPos.Y + side), 0.0f, 1.0f),
				 color.ToArgb());


			// Drawing square.
			d3dDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Verts);
		}


		/// <summary>
		/// The Direct3D device object.
		/// </summary>
		private Device d3dDevice;
	}
}
